//
//  MenuListTableViewCell.m
//  项目三
//
//  Created by rimi1 on 2016/12/7.
//  Copyright © 2016年 Wangxingqian. All rights reserved.
//

#import "MenuListTableViewCell.h"

static NSInteger spacing_ = 10;

@implementation MenuListTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self.contentView addSubview:self.backView];
        [self.backView addSubview:self.imageViewList];
        [self.backView addSubview:self.name];
        [self.backView addSubview:self.foodImage];
        [self.backView addSubview:self.food];
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    CGRect rect = self.food.frame;
    rect.size.width = kWIDTH - CGRectGetMaxX(self.foodImage.frame) - spacing_;
    self.food.frame = rect;
    [self.food sizeToFit];
}

#pragma mark - get

- (UIView *)backView {
    
    if (!_backView) {
        
        _backView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kWIDTH, WXQAdaptionHeight(100))];
        _backView.backgroundColor = [UIColor whiteColor];
        _backView.layer.shadowColor = [UIColor blackColor].CGColor;
        _backView.layer.shadowOffset = CGSizeMake(0, 5);
        _backView.layer.shadowOpacity = 0.1;
        
    }
    return _backView;
}

- (UIImageView *)imageViewList {
    
    if (!_imageViewList) {
        
        CGFloat height = WXQAdaptionHeight(80);
        _imageViewList = [[UIImageView alloc] initWithFrame:CGRectMake(WXQAdaptionWidth(spacing_), WXQAdaptionHeight(spacing_), WXQAdaptionWidth(100), height)];
        _imageViewList.layer.borderColor = [UIColor lightGrayColor].CGColor;
        _imageViewList.layer.borderWidth = 1;
        _imageViewList.layer.cornerRadius = 5;
        _imageViewList.layer.masksToBounds = YES;
        
    }
    return _imageViewList;
}

- (UILabel *)name {
    
    if (!_name) {
        
        CGFloat x = CGRectGetMaxX(self.imageViewList.frame) + WXQAdaptionWidth(spacing_);
        CGFloat height = WXQAdaptionHeight(16);
        _name = [[UILabel alloc] initWithFrame:CGRectMake(x, CGRectGetMinY(self.imageViewList.frame) + WXQAdaptionHeight(spacing_), kWIDTH - x - WXQAdaptionWidth(spacing_), height)];
        _name.font = [UIFont systemFontOfSize:height];
        
    }
    return _name;
}

- (UIImageView *)foodImage {
    
    if (!_foodImage) {
        
        CGFloat width = WXQAdaptionHeight(20);
        _foodImage = [[UIImageView alloc] initWithFrame:CGRectMake(CGRectGetMinX(self.name.frame), CGRectGetMaxY(self.name.frame) + WXQAdaptionHeight(spacing_ + 5), width, width)];
        _foodImage.image = [UIImage imageNamed:@"材料"];
        
    }
    return _foodImage;
}

- (UILabel *)food {
    
    if (!_food) {
        
        CGFloat x = CGRectGetMaxX(self.foodImage.frame) + WXQAdaptionWidth(spacing_);
        _food = [[UILabel alloc] initWithFrame:CGRectMake(x, CGRectGetMinY(self.foodImage.frame), kWIDTH - x - WXQAdaptionWidth(spacing_), CGRectGetHeight(self.foodImage.bounds))];
        _food.font = [UIFont systemFontOfSize:WXQAdaptionHeight(14)];
        _food.numberOfLines = 2;
        _food.textColor = [UIColor lightGrayColor];
        
    }
    return _food;
}

@end
